//
//  ZNewMissionVC.m
//  WeClubs
//
//  Created by Zed Link on 21/4/2017.
//  Copyright © 2017 Zed. All rights reserved.
//

#import "ZNewMissionVC.h"
#import "ZMissionRemarksVC.h"
#import "ZMemberChoseVC.h"
@interface ZNewMissionVC ()


@end

static NSString *ZNewMissionCellID = @"ZNewMissionCellID";
static NSString *ZCellID = @"ZCellID";
@implementation ZNewMissionVC

#pragma mark - About Navigation
-(void)viewDidLoad{

    [super viewDidLoad];
    
    [self.mainView registerNib:[UINib nibWithNibName:@"ZNewMemberGroupCell" bundle:nil] forCellReuseIdentifier:ZNewMissionCellID];
    
 
}
- (void)zConfigNavigation
{
    [super zConfigNavigation];
    
    [self zAddBackItemWithGesture:YES];
    self.navigationItem.title = @"任务发布";
    self.navigationItem.rightBarButtonItem = [self zNavItemWithTitle:@"发布" andSelector:@selector(newMeetingAction)];
}

- (void)newMeetingAction
{
    // Todo: 发布会议
    
    [self.navigationController popViewControllerAnimated:YES];
}


#pragma mark - Setter && Getter Methods
- (void)setDataArr:(NSMutableArray *)dataArr{
    
    _dataArr = dataArr;
       ZLog(@"content:%@",_content);
    [self.mainView reloadData];
}
- (void)setContent:(NSString *)content{

    _content = content;
    [self.mainView reloadData];

}
#pragma mark - UITableViewDelegate & UITableViewDataSource

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    
    return self.interfaceConfig.count;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    if (section == 4) {
        if (self.dataArr.count > 0) {
            return 1;
        }else{
            return 0;
        }
    }
    return 1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    
    switch (indexPath.section) {
        case ZNewCellTypeTextField:{
            ZNewTextViewCell *cell = [tableView dequeueReusableCellWithIdentifier:NewTextViewCellReuseID];
            [cell setPlaceHolderText:@"请输入通知内容"];
            
            Z_WEAK_SELF;
            cell.textViewTextHandlerCallBack =^(NSString *textF){
                
                weakSelf.content  = textF;
            };
            
            return cell;
        }
            break;
        case 1:
        case 2:{
            
            UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ZCellID];
            if (cell == nil) {
                cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:ZCellID];
                
            }
            cell.textLabel.text = indexPath.section ==1 ? @"备注":@"任务截止时间";
            cell.backgroundColor = [UIColor yellowColor];
            cell.detailTextLabel.text = indexPath.section ==1 ?_content:@"2017-04-01 19:00";

            return cell;
            
        }
            break;
        case 3:{
            ZNewMemberChoseCell *cell = [tableView dequeueReusableCellWithIdentifier:NewMemberChoseCellReuseID];
            return cell;
        }
        case 4:{
            if (self.dataArr.count>0) {
                ZNewMemberGroupCell *cell = [tableView dequeueReusableCellWithIdentifier:ZNewMissionCellID];
                cell.nameLabel.text = _club_name;
                cell.dataArr = self.dataArr;
                cell.countLabel.text = [NSString stringWithFormat:@"%zd人",_dataArr.count];
                cell.backgroundColor = [UIColor redColor];
                return cell;
            }else{
                return nil;
            }
        }
            break;
        default:
            return nil;
            break;
    }
    return nil;

}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if (indexPath.section == 4) {
        if (self.dataArr.count >0) {
            return 120;
        }else{
            return 0;
        }
    }else if (indexPath.section ==0){
        
        return 200;
    }
    return 50;
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    /**
     备注 1  0
     任务截止时间1 1
     请选择社团成员 2 0
     */
    ZLog(@"%zd-------%zd ",indexPath.section,indexPath.row);

    
    switch (indexPath.section) {
        case 1:
            if (indexPath.row == 0) {
                ZMissionRemarksVC *remearkVc =  [[ZMissionRemarksVC alloc]init];
            [self.navigationController pushViewController:remearkVc animated:YES];
                
            }else if (indexPath.row ==1){
            
            
            }
            
            break;
            
         case 3:
            
            if (indexPath.row == 0) {
                
                // 选择社团成员
                ZMemberChoseVC *vc = [ZMemberChoseVC zNew];
                [self.navigationController pushViewController:vc animated:YES];
                
            }
            
            break;
        default:
            break;
    }
}
@end

